package main

import (
	"time"

	"gitee.com/sillyman/mixlog"

	"gitee.com/sillyman/WebCrawler/dispatcher"
	"gitee.com/sillyman/WebCrawler/requester"
	"gitee.com/sillyman/WebCrawler/urlqueue"
)

func main() {
	db, err := initORM()
	if err != nil {
		mixlog.Fatalf("初始化ORM：%s", err.Error())
	}
	mixlog.Info("已初始化ORM")

	// URL列队
	queue, err := urlqueue.NewQueueInDBS(db)
	if err != nil {
		mixlog.Fatalf("创建 URL 列队：%s", err.Error())
	}
	mixlog.Info("已创建 URL 列队")

	// HTTP 请求者
	httpRequester := requester.NewRequester(10*time.Second, nil, generateOnResponseHandle(db, queue))

	// 调度员
	d := dispatcher.New(httpRequester, queue, time.Second, 3*time.Second)

	// 监听进程信号
	goListingSignal(func() {
		d.Quit()
	})

	// 开始调度
	d.Loop("https://bookfere.com/essay")
}
